package com.yz.lzq.liwushuo.model;

import com.yz.lzq.liwushuo.bean.GiftTuiJianBean;
import com.yz.lzq.liwushuo.interfaces.GiftInterface;
import com.yz.lzq.liwushuo.util.UrlConfig;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by AdminJia on 2016/11/26.
 */

public class GiftTuiJianBiz implements IGiftTuiJianBiz {
    @Override
    public void loadTuiJianData(final OnGiftTuiJianGetDataListener listener, int offset) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(UrlConfig.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create()).build();
        GiftInterface.GiftTuiJianInterface giftTuiJianInterface = retrofit.create(GiftInterface.GiftTuiJianInterface.class);
        Call<GiftTuiJianBean> call = giftTuiJianInterface.getTuiJianData(offset);
        call.enqueue(new Callback<GiftTuiJianBean>() {
            @Override
            public void onResponse(Call<GiftTuiJianBean> call, Response<GiftTuiJianBean> response) {
                GiftTuiJianBean body = response.body();
                List<GiftTuiJianBean.DataBean.ItemsBean> items = body.getData().getItems();
                String header_url = body.getData().getCover_webp();
                listener.success(items, header_url);
            }

            @Override
            public void onFailure(Call<GiftTuiJianBean> call, Throwable t) {
                listener.failed(t);
            }
        });


    }


}
